package cn.edu.xmu.rocketmqdemo.service.mq;


import cn.edu.xmu.rocketmqdemo.dao.OrdersDao;
import cn.edu.xmu.rocketmqdemo.model.Log;
import cn.edu.xmu.rocketmqdemo.model.Order;
import cn.edu.xmu.rocketmqdemo.model.OrderVo;
import cn.edu.xmu.rocketmqdemo.model.VoObject;
import cn.edu.xmu.rocketmqdemo.service.RocketMQService;
import cn.edu.xmu.rocketmqdemo.util.JacksonUtil;
import cn.edu.xmu.rocketmqdemo.util.ResponseCode;
import cn.edu.xmu.rocketmqdemo.util.ReturnObject;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@RocketMQMessageListener(topic = "order-topic", consumeMode = ConsumeMode.CONCURRENTLY, consumeThreadMax = 10, consumerGroup = "order-group")
public class OrderConsumerListener implements RocketMQListener<String> {

    private static final Logger logger = LoggerFactory.getLogger(OrderConsumerListener.class);
    @Autowired
    public OrdersDao ordersDao;
    @Override
    public void onMessage(String orderVoString) {
        System.out.println("开始处理消息");
        OrderVo orderVo = JacksonUtil.toObj(orderVoString, OrderVo.class);//json转对象
        ReturnObject<Object> returnOrder = ordersDao.createNewOrder(orderVo.createOrder());
    }
}
